$(function(){
	var able = "input[disabled!='disabled'][readonly!='readonly'][type!='hidden'],select[disabled!='disabled'][readonly!='readonly'],textarea[disabled!='disabled'][readonly!='readonly']";
	var ableSelect = "select[disabled!='disabled'][readonly!='readonly']";
	var formName = ".form";
	$(window).bind("keyup",function(){
		var allAbles = $(formName).find(able);
		$(formName).find(ableSelect).unbind("keydown").bind("keydown",function(){
			var keycode2 = event.which||event.keyCode;
			if(keycode2==37||keycode2==39||keycode2==13){
				return false;
			}
		});
		var currentFouse = $(formName).find(":focus");
		if(null==currentFouse){
			$(able).get(0).focus();
			$(able).get(0).select();
		}
		var keycode = event.which||event.keyCode;
		var current = null;
		switch(keycode){
	      case 37://Left
	    	  var current = $(allAbles).get($(allAbles).index($(currentFouse))-1);
	    	  if($(current).hasClass("hide")){
	    		  current = $(allAbles).get($(allAbles).index($(current))-1);
	    	  }
	    	  break;
	      case 38://Up
	    	  if($(currentFouse).attr("type")=="number"){
	    		  break;
	    	  }
	    	  if($(currentFouse).is("select")){
	    		  break;
	    	  }
	    	  var current = $(allAbles).get($(allAbles).index($(currentFouse))-1);
	    	  if($(current).hasClass("hide")){
	    		  current = $(allAbles).get($(allAbles).index($(current))-1);
	    	  }
	    	  break;
	      case 39://Right
	    	  var current = $(allAbles).get($(allAbles).index($(currentFouse))+1);
	    	  if($(current).hasClass("hide")){
	    		  current = $(allAbles).get($(allAbles).index($(current))+1);
	    	  }
	    	  break;;
	      case 40://Down
	    	  if($(currentFouse).attr("type")=="number"){
	    		  break;
	    	  }
	    	  if($(currentFouse).is("select")){
	    		  break;
	    	  }
	    	  var current = $(allAbles).get($(allAbles).index($(currentFouse))+1);
	    	  if($(current).hasClass("hide")){
	    		  current = $(allAbles).get($(allAbles).index($(current))+1);
	    	  }
	    	  break;
	      case 13://Enter
	    	  var current = $(allAbles).get($(allAbles).index($(currentFouse))+1);
	    	  if($(current).hasClass("hide")){
	    		  current = $(allAbles).get($(allAbles).index($(current))+1);
	    	  }
	    	  break;
		}
		if(null!=current){
			$(current).focus();
			$(current).select();
		}
	});
});